home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
qtawk
/
getdir.exp
< prev
next >
Wrap
Text File
|
1990-07-25
|
4KB
|
100 lines
# QTAwk utility to read directory for specified files
#
# file patterns are listed on the command line. Note that the syntax for
# patterns follows the regular expression syntax and not the wildcard
# syntax of DOS. For example the DOS wildcard expression for all files
# ending in "exp" would be:
# "*.exp"
# the regular expression syntax is:
# ".*\.exp"
#
# The regular expression syntax is a little more involved, but can
# specify patterns that the DOS wildcard syntax cannot. For example, to find
# all files starting with 'd', 'g' or 'h' and with an extension of
# "hlp" or "txt", we would have the command line:
# QTAwk -fgetdir.exp "[gdh].*\.(hlp|txt)"
# This is simply not possible with the DOS wildcard notation. Multiple
# patterns may also be specified:
# QTAwk -fgetdir.exp "[gdh].*\.(hlp|txt)" ".*(dir|bnc)\.exp"
#
# The user function defined to find and print the desired filenames may be
# extended to also include expressions for the file date/time/size to further
# narrow down the files desired.
#
BEGIN {
local pattern;
local sub_dir = ""; # default to current sub-directory
for ( i = 1 ; i < ARGC ; i++ ) {
pattern = '^' ∩ strupr(ARGV[i]) ∩ '$';
#
# the following two lines will convert the command line string
# into a regular expression. This is to prevent the constant
# conversion of a string into a regular expression in the
# "getdir" function. The following two lines could be deleted or
# commented out without degrading the performance too much
#
pattern = "pattern = /" ∩ pattern ∩ "/;";
execute(pattern);
#
# print pattern to look for as a double check, could be commented out
# when not necessary
#
print "Finding: " ∩ pattern;
#
# go find matching files and print names
#
getdir(sub_dir,pattern);
}
}
# Function to get desired file names and print
# Use DOS "dir" command to list all files to a temporary file
# read temporary file picking up:
# 1) path from third line
# 2) filenames from remainder of lines
# 3) match filenames against filepattern for desired files and print if match
# Could also get file sizes, dates and times if desired
# Possible extension:
# 1) It would be possible to check each line for the pattern
# /<DIR>/ and find subdirectories. A tree traversal could then be done with
# complete regular expression control of the path through the tree.
# 2) Add logic to check file size, date and/or time for matches against
# desired criteria. The criteria could be in a preset file or a file passed
# on the command line. The criteria could be expressed as arithmetic and/or
# logical equations. The equations could be executed with the "execute"
# function. The return value could then be checked for true/false and the
# file accepted/rejected accordingly.
#
# Arguments passed:
# dir ==> path of desired files
# file_template ==> string or regular expression pattern for filenames
#
function getdir(dir,file_template) {
local tmp_file = "$tmptmp$.dir";
local gdir = "dir " ∩ dir ∩ "*.* > " ∩ tmp_file;
local ddir = "del " ∩ tmp_file;
local tmparr, inline, filename;
system(gdir);
fgetline(tmp_file,inline); # read and discard header lines
fgetline(tmp_file,inline); # read and discard header lines
fgetline(tmp_file,inline); # read and discard header lines
split(inline,tmparr); # split out to get path
path = tmparr[3] ∩ '\\'; # set path
# print path; # un-comment to print path
fgetline(tmp_file,inline); # read and discard header lines
while ( fgetline(tmp_file,inline) > 0 ) {
# discard if not a filename line
if ( inline !~ "^[A-Z]" ) continue;
# split out file information
nf = split(inline,tmparr);
# form "filename.ext"
filename = tmparr[1] ∩ '.' ∩ tmparr[2];
if ( filename ~~ file_template ) print filename;
}
# delete temporary directory file
close(tmp_file);
system(ddir);
}